package cl.uchile.sketchpad.persistance.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Entity;

import static javax.persistence.FetchType.*;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Entity
@Table(name = "group_")
@JsonIgnoreProperties({"slides","users","activity"})
public class Group implements Serializable {
	
	public static enum Type {
		WORK("work"), NOTES("notes");
		
		private String value;
		
		private Type(String value){
			this.value = value;
		}
		
		public String getValue() {
			return this.value;
		}
	}
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2742585504045980674L;
	private Integer id;
	private String name;
	private String type;

	private Activity activity;
	private User author;
	
	private List<User> users = new ArrayList<User>(0);
	private Set<Slide> slides = new LinkedHashSet<Slide>(0);

	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Id
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "type")
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@ManyToMany(fetch = LAZY)
	@JoinTable(name = "group_user", 
		joinColumns = { @JoinColumn(name = "group_id") }, 
		inverseJoinColumns = { @JoinColumn(name = "user_id") })
	@OrderBy("name")
	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	@OneToMany(fetch = LAZY, mappedBy = "group")
	public Set<Slide> getSlides() {
		return slides;
	}

	public void setSlides(Set<Slide> slides) {
		this.slides = slides;
	}

	@ManyToOne(fetch = LAZY)
	@JoinColumn(name = "activity_id")
	public Activity getActivity() {
		return activity;
	}

	public void setActivity(Activity activity) {
		this.activity = activity;
	}

	
	@ManyToOne(fetch = EAGER)
	@JoinColumn(name = "author_id")
	public User getAuthor() {
		return author;
	}

	public void setAuthor(User author) {
		this.author = author;
	}

}
